package com.punch.common.simple.redis.utils;

import com.punch.common.constant.CommonConstant;
import com.punch.common.dto.user.user.RedisUserDTO;
import com.punch.common.utils.ServletUtil;
import com.punch.common.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UserUtil {

    private static RedisUtil<RedisUserDTO> redisUtil = SpringUtil.getBean(RedisUtil.class);

    public static RedisUserDTO getLoginUser() {
        Long userId = Long.valueOf(ServletUtil.getRequest().getHeader("userId"));
        String clientType = ServletUtil.getRequest().getHeader("clientType");
        StringBuilder sb = new StringBuilder();
        sb.append(CommonConstant.SECURITY_REDIS_USER_PREFIX).append(clientType).append(":").append(userId);
        return redisUtil.getValue(sb.toString());
    }

    public static Long getLoginUserId() {
        Long userId = Long.valueOf(ServletUtil.getRequest().getHeader("userId"));
        return userId;
    }
}
